package com.romotc.qqrobot.webqq.qqInterfaceLog;

import java.util.List;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.qqrobot.bean.QQUserFriend;
import com.romotc.qqrobot.bean.RobotUser;
import com.romotc.qqrobot.bean.RobotUserService;
import com.romotc.qqrobot.bean.RobotUserSubQq;
import com.romotc.qqrobot.bean.RobotUserSubQqService;
import com.romotc.qqrobot.config.bean.QQUrlWatcherConfig;
import com.romotc.scache.RequestSpy;

/**
 * 记录 http://s.web2.qq.com/api/get_user_friends2 请求日志
 * @author Administrator
 *
 */
public class Get_user_friends2_Log implements QQUrlLogInterface {

	@Override
	public boolean checkSkipLog(RequestSpy rqSpy, QQUrlWatcherConfig config) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean logRequestSpy(RequestSpy rqSpy, QQUrlWatcherConfig config) {
		//获取到的好友信息
		List<QQUserFriend> qqUserFriends = QQUserFriend.buildQQUserFriends(rqSpy); 
		
		if(qqUserFriends != null && !qqUserFriends.isEmpty()) {
			QQLogedin curQQ = QQLogedin.getCurQqLogedIn(rqSpy);
			
			//设置好友数量
			RobotUserSubQq subQq = RobotUserSubQqService.qrySubQQ(curQQ.getUin());
			if(subQq != null) {
				subQq.setFriendsSize(qqUserFriends.size());
				subQq.Delete();
				subQq.Save();
			}else {
				RobotUser user = RobotUserService.qryUser(curQQ.getUin());
				user.setFriendsSize(qqUserFriends.size());
			}
		}
		return true;
	}
	
	

}
